//
//  ViewController.swift
//  Swift_Study
//
//  Created by apple on 2018/9/25.
//  Copyright © 2018年 dminfo. All rights reserved.
//

import UIKit
// MARK:- 准备数据
 var kSize = UIScreen.main.bounds
 var tbvMain:UITableView!
 var dataArr = ["SimpleStopWatch-01","CustomFont-02","CollectionView-03"]
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

  override func viewDidLoad() {
    super.viewDidLoad()
     view.backgroundColor = UIColor.white
     makeTable()
  }
//  初始化tbv
  func makeTable () {
    tbvMain = UITableView.init(frame:CGRect(x: 0, y: 60, width: kSize.width, height: kSize.height - 60),style:.plain)
    tbvMain.delegate = self
    tbvMain.dataSource = self
    view.addSubview(tbvMain)
    tbvMain.tableFooterView = UIView.init()
  }
  
// MARK:- 代理
//  组
  func numberOfSections(in tableView: UITableView) -> Int {
    return 1
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return dataArr.count
  }
//cell
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellId = "cellId"
    var cell = tableView.dequeueReusableCell(withIdentifier: cellId)
    if cell == nil {
      cell = UITableViewCell(style:UITableViewCellStyle.default,reuseIdentifier:cellId)
    }
    cell?.textLabel?.text = dataArr[indexPath.row]
    return cell!
  }
  
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 60
  }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.row == 0 {
      let vc = SimpleStopWatchVC.init()
      navigationController?.pushViewController(vc, animated: true)
    }else if indexPath.row == 1 {
      let vc = CustomFontVC.init()
      navigationController?.pushViewController(vc, animated: true)
    }else if indexPath.row == 2 {
      let vc = CollectionViewVC.init()
      navigationController?.pushViewController(vc, animated: true)
    }
  
  }
  
  

}

